import Api from "Api/index";
import store from "../store/index.js";
import * as common from "Commons/index";
import orderStatus from "./order_status.js"
// import ShopApi from 'Api/shop/index';
// import ugcApi from 'Api/ugc/index';

// Behavior文档 https://developers.weixin.qq.com/miniprogram/dev/reference/api/Behavior.html
const globalBehavior = Behavior({
    behaviors: [],
    data: {},
    lifetimes: {
        attached() {
            const onLoad = this.onLoad
            this.onLoad = function (options = {}) {
                // TODO: 每个页面onLoad之前的逻辑可以写在这里
                if (options.scene) {
                }

                return onLoad.call(this, options)
            }
        },
    },
    methods: {
        // 获取用户信息
        getMemberProfileFun(){
            return new Promise((resolve, reject)=> {
                Api.userInfomMemberProfile().then(res=>{
                    res = res.result||{};

                    res.nickname = common.wxNickname(res.nickname);
                    res.headimgurl = common.wxHeadimgurl(res.headimgurl);
                    this.setState("memberProfile",res)
                    resolve(res);
                });
            });
        },
        // 订单状态
        orderStatusTextFun(item){
            let text = '';
            if( item.order_status==100 ){
              text = '待付款';
            }else if( item.order_status==101 ){
              text = '待发货';
            }else if( item.order_status==201 ){
              text = '商家接单';
            }else if( item.order_status==202 ){
                text = '等待收货';
            }else if( item.order_status==301 ){
                text = '已签收';
            }else if( item.order_status==402 ){
                text = '已归还';
            }
            
            else if( item.order_status==501||item.order_status==502 ){
                text = '已取消';
            }
            
            else if( item.order_status==601 ){
                text = '管理员-退押金';
            }else if( item.order_status==602 ){
                text = '管理员-操作退款';
            }else if( item.order_status==603 ){
                text = "自己-已退款"
            }else{
                text = item.order_status
            }
            return text;
        },

        // 订单取消通知
        // yFtecq3KoCUkCTIUtTxcrzzGUW2uuJ_2Zv-S8Z4OSRA
        

        // 全局分享配置
        onShareAppMessage(options) {
            let dataset = options.target&&options.target.dataset||{};
            let shareObj = {
                title: '设备租赁',
                path: `/pages/index/index`,
                imageUrl: '',
            };
            if( options.from=='button' ){
                shareObj = {
                    title: dataset.title||shareObj.title,
                    imageUrl: dataset.imgurl||shareObj.imageUrl,
                    path: dataset.path||shareObj.path,
                }
            }
            shareObj.promise = promise;
            return shareObj;
        },
    }
})

export default globalBehavior
